package com.prtek.reminder.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.prtek.reminder.R;
import com.prtek.reminder.bean.User;

/**
 * @author Jarly
 * @Description:
 * @date 2018年7月27日
 */
public class ContactSelectView extends RelativeLayout {

  private CheckBox mCheckBox;
  private TextView mUserName;
  private ImageView mUserIcon;

  private RequestOptions mRequestOptions =
      new RequestOptions().diskCacheStrategy(DiskCacheStrategy.NONE)
          .skipMemoryCache(true)
          .error(R.mipmap.contact_avatar_default);

  public ContactSelectView(Context context) {
    this(context, null);
  }

  public ContactSelectView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
  }

  private void init() {
    LayoutInflater.from(getContext()).inflate(R.layout.contact_window_gv_item, this);
    mCheckBox = (CheckBox) findViewById(R.id.checkbox_contact);
    mUserName = (TextView) findViewById(R.id.home_item_name);
    mUserIcon = (ImageView) findViewById(R.id.home_item_icon);
  }

  public void bindNormalView(User contact) {
    mCheckBox.setChecked(contact.isSelected());
    mUserName.setText(contact.getName());
    Glide.with(getContext()).load(contact.getImage()).apply(mRequestOptions).into(mUserIcon);
  }
}
